#ifndef COMMON_H
#define COMMON_H
#include <QFileInfo>
#include <QFileInfoList>
#include <QScrollArea>
#include <QDir>
#include <QString>
#include <QMap>
#include <QObject>  //tr翻译需要

extern bool g_preview;

const QStringList ui_type_list = {QObject::tr("screen"),
                                  QObject::tr("partition"),
                                  QObject::tr("layout"),
                                  QObject::tr("item"),
                                  QObject::tr("material")};
const QStringList screen_type_list = {QObject::tr("左板式"),
                                      QObject::tr("图片全屏紧急信息"),
                                      QObject::tr("文本全屏紧急信息")};
const QStringList item_type_list = {QObject::tr("text"),
                                    QObject::tr("video"),
                                    QObject::tr("image")};
const QStringList content_list =
{
    QObject::tr("(#start_station#)"),
    QObject::tr("(#start_station1#)"),
    QObject::tr("(#start_station2#)"),
    QObject::tr("(#end_station#)"),
    QObject::tr("(#end_station1#)"),
    QObject::tr("(#end_station2#)"),
    QObject::tr("(#current_station#)"),
    QObject::tr("(#next_station#)"),
    QObject::tr("(#cur_next_station#)"),
    QObject::tr("(#cur_next_station1#)"),
    QObject::tr("(#cur_next_station2#)"),
    QObject::tr("(#cur_next_station_text#)"),
    QObject::tr("(#cur_next_station_text1#)"),
    QObject::tr("(#cur_next_station_text2#)"),
    QObject::tr("(#cabN_internal_temp#)"),
    QObject::tr("(#cabN_external_temp#)"),
    QObject::tr("(#cabN_hr#)"),
    QObject::tr("(#cabN_crowd_picture#)"),
    QObject::tr("(#emergency_picture#)"),
    QObject::tr("(#year#)"),
    QObject::tr("(#month#)"),
    QObject::tr("(#day#)"),
    QObject::tr("(#hour#)"),
    QObject::tr("(#minute#)"),
    QObject::tr("(#second#)"),
    QObject::tr("(#week_cn#)"),
    QObject::tr("(#week_en#)"),
    QObject::tr("(#scroll_text#)"),
    QObject::tr("(#title#)"),
    QObject::tr("(#message1#)"),
    QObject::tr("(#message2#)"),
};

const QMap<QString, QString> preview_map =
{
    { QObject::tr("(#start_station#)"), "唯亭"},
    { QObject::tr("(#start_station1#)"), "唯亭"},
    { QObject::tr("(#start_station2#)"), "Weiting"},
    { QObject::tr("(#end_station#)"), "花桥"},
    { QObject::tr("(#end_station1#)"), "花桥"},
    { QObject::tr("(#end_station2#)"), "Huaqiao"},
    { QObject::tr("(#current_station#)"), "金沙江路"},
    { QObject::tr("(#next_station#)"), "洞庭湖路"},
    { QObject::tr("(#cur_next_station#)"), "金沙江路"},
    { QObject::tr("(#cur_next_station1#)"), "金沙江路"},
    { QObject::tr("(#cur_next_station2#)"), "Jinshajiang lu"},
    { QObject::tr("(#cur_next_station_text#)"), "当前站"},
    { QObject::tr("(#cur_next_station_text1#)"), "当前站"},
    { QObject::tr("(#cur_next_station_text2#)"), "Current Station"},
    { QObject::tr("(#cab1_internal_temp#)"), "20"},
    { QObject::tr("(#cab2_internal_temp#)"), "20"},
    { QObject::tr("(#cab3_internal_temp#)"), "20"},
    { QObject::tr("(#cab4_internal_temp#)"), "20"},
    { QObject::tr("(#cab5_internal_temp#)"), "20"},
    { QObject::tr("(#cab6_internal_temp#)"), "20"},
    { QObject::tr("(#cab1_external_temp#)"), "25"},
    { QObject::tr("(#cab2_external_temp#)"), "25"},
    { QObject::tr("(#cab3_external_temp#)"), "25"},
    { QObject::tr("(#cab4_external_temp#)"), "25"},
    { QObject::tr("(#cab5_external_temp#)"), "25"},
    { QObject::tr("(#cab6_external_temp#)"), "25"},
    { QObject::tr("(#cab1_hr#)"), "30"},
    { QObject::tr("(#cab2_hr#)"), "30"},
    { QObject::tr("(#cab3_hr#)"), "30"},
    { QObject::tr("(#cab4_hr#)"), "30"},
    { QObject::tr("(#cab5_hr#)"), "30"},
    { QObject::tr("(#cab6_hr#)"), "30"},
//    { QObject::tr("(#cabN_crowd_picture#)"), },
//    { QObject::tr("(#emergency_picture#)"), },
    { QObject::tr("(#year#)"), "2022"},
    { QObject::tr("(#month#)"), "3"},
    { QObject::tr("(#day#)"), "25"},
    { QObject::tr("(#hour#)"), "14"},
    { QObject::tr("(#minute#)"), "12"},
    { QObject::tr("(#second#)"), "00"},
    { QObject::tr("(#week_cn#)"), "星期五"},
    { QObject::tr("(#week_en#)"), "Friday"},
    { QObject::tr("(#scroll_text#)"), "欢迎乘坐苏州轨道交通"},
    { QObject::tr("(#title#)"), "临时停车广播"},
    { QObject::tr("(#message1#)"), "各位尊敬的乘客，现在是临时停车，请您稍候，为了您和他人的安全，请勿触动车上的设备，感谢您的谅解与合作。"},
    { QObject::tr("(#message2#)"), "Attention, please. The train has stopped temporarily. Please wait a minute. For yours and others safety, please do not move any equipment on the train. Thank you."}
};

const QStringList explain_list =
{
    QObject::tr("起始站（语言自动切换）"),
    QObject::tr("起始站（固定第一语言）"),
    QObject::tr("起始站（固定第二语言）"),
    QObject::tr("终点站（语言自动切换）"),
    QObject::tr("终点站（固定第一语言）"),
    QObject::tr("终点站（固定第二语言）"),
    QObject::tr("当前站（语言自动切换）"),
    QObject::tr("下一站（语言自动切换）"),
    QObject::tr("当前站/下一站（语言自动切换）"),
    QObject::tr("当前站/下一站（固定第一语言）"),
    QObject::tr("当前站/下一站（固定第二语言）"),
    QObject::tr("当前站文本/下一站文本（语言自动切换）"),
    QObject::tr("当前站文本/下一站文本（固定第一语言）"),
    QObject::tr("当前站文本/下一站文本（固定第二语言）"),
    QObject::tr("车厢内部温度，N为车厢号，从1开始"),
    QObject::tr("车厢外部温度，N为车厢号，从1开始"),
    QObject::tr("车厢湿度，N为车厢号，从1开始"),
    QObject::tr("车厢拥挤度图片，N为车厢号，从1开始"),
    QObject::tr("全屏紧急消息图片"),
    QObject::tr("年"),
    QObject::tr("月"),
    QObject::tr("日"),
    QObject::tr("小时"),
    QObject::tr("分"),
    QObject::tr("秒"),
    QObject::tr("中文星期"),
    QObject::tr("英文星期"),
    QObject::tr("滚动消息"),
    QObject::tr("全屏紧急消息文本标题"),
    QObject::tr("全屏紧急消息文本正文1"),
    QObject::tr("全屏紧急消息文本正文2"),
};
struct ProjectData
{
    QString name;
    int width;
    int height;
    QString path;
    QString type;
};

extern ProjectData g_pro_data;

/*枚举*/
/*窗口类型*/
enum StackWidget
{
    page_start = 0,
    page_edit  = 1,
};

enum ObserverMsgType
{
    loss_select_msg       = 0,
    
    item_select_msg       = 1,
    layout_select_msg     = 2,
    partition_select_msg  = 3,
    screen_select_msg     = 4,
};

enum AlignType
{
    align_left   = 0,
    align_center = 1,
    align_right  = 2,
};

/*公共方法*/
QFileInfoList getFileList(const QString& path);
void setBgColor(QWidget *parent, const QString &color);
void replaceQss(QString &qss, QString key, QString replace_str);
bool addDoubleQuotationMark(QString path);
bool delDoubleQuotationMark(QString path);


/*纯数据结构，参照format_lcd.json板式配置文件*/
/*path_prefix*/
struct PathPrefix
{
    QString file;
    QString url;
};

/*video_stream*/
struct Live
{
    QString ip;
    int port;
    int interface;
};
struct VideoStream
{
    int stream_destination;
    QList<Live> lives;
    QString local;
};

/*resolution*/
struct Resolution
{
    int width;
    int height;
};

/*screens*/
struct Material
{
    int id;
    int duration;
    QString content;
};
struct Stream_index
{
    int all;
};
struct Data
{
    Stream_index stream_index;
    QMap<int, Material> materials;
};
struct CabPosItem
{
    int id;
    int x;
    int y;
    int width;
    int height;
    int size;
    int align;
    int effect;
    int speed;
    bool bold;
    bool italic;
    bool sound;
    QString type;
    QString font;
    QString fore_color;
    QString back_color;
    QString background;
    QString background_color;
    Data data;
};
struct Item
{
    int id;
    QMap<QString, CabPosItem> cabpositems;
};
struct Layout
{
    int id;
    int duration;
    QList<Item> items;
};
struct Common
{
    int x;
    int y;
    int width;
    int height;
    int z_order;
    bool transparent;
    QString background;
    QString background_color;
};
struct Partition
{
    int id;
    Common common;
    QMap<int, Layout> layouts;
};
struct Screen
{
    int id;
    QString name;
    QMap<int, Partition> partitions;
};




Q_DECLARE_METATYPE(Screen)

#endif // COMMON_H
